﻿#region Using Statements
using System;
using System.Text;
using GameBase.Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StarFox.ScreenComponents;
#endregion

#if DEBUG
namespace StarFox.Testing
{
    /// <summary>
    /// Display of testing information collected throughout the game.
    /// <para>Use this class for testing purposes only.</para>
    /// </summary>
    public class TestInfo : ScreenComponent2D
    {
        #region Fields

        StringBuilder strBuffer;
        SpriteFont font;
        Vector2 pos;

        TestInput input;
        bool showInfo;

        #endregion

        #region Screen Transitions

        /// <summary>
        /// Makes the ScreenComponent2D transition to visible state.
        /// </summary>
        public override void Show() { }

        /// <summary>
        /// Makes the ScreenComponent2D transition to hidden state.
        /// </summary>
        public override void Hide() { }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="screen">The Screen that this ScreenComponent2D is associated to.</param>
        public TestInfo(Screen screen)
            : base(screen)
        {
            strBuffer = Game.Services.GetService(typeof(StringBuilder)) as StringBuilder;
            if (strBuffer == null)
                throw new InvalidOperationException("Service of type StringBuilder not found");

            input = Game.Services.GetService(typeof(TestInput)) as TestInput;
            if (input == null)
                throw new InvalidOperationException("Service of type TestInput not found");

            font = Screen.Content.Load<SpriteFont>(ContentSettings.GetAsset("FONT_TEST"));
            pos = new Vector2(Screen.Width * 0.025f, Screen.Height * 0.15f);
        }

        #endregion

        #region Update

        /// <summary>
        /// Called when the ScreenComponent2D needs to be updated.
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to this method.</param>
        public override void Update(GameTime gameTime)
        {
            if (input.IsShowTestInfo(Screen.PlayerIndex)) { showInfo = !showInfo; }
        }

        #endregion

        #region Draw

        /// <summary>
        /// Called when the ScreenComponent2D needs to be drawn.
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to this method.</param>
        public override void Draw(GameTime gameTime)
        {
            if (showInfo)
            {
                SpriteBatch.DrawString(font, strBuffer, pos, Color.Fuchsia,
                                       0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            }
        }

        #endregion
    }
}
#endif
